using System;
using DevExpress.Xpo;
using SmartPeople.Framework.SecuritySpace;

namespace SmartPeople.Framework.Security.Providers.XPO
{
    [Persistent("SecurityApplication")]
    internal class XPSecurityApplication : XPCustomObject, ISecurityApplication
    {
        public XPSecurityApplication(Session session) : base(session)
        {
            // This constructor is used when an object is loaded from a persistent storage.
            // Do not place any code here.
        }

        public XPSecurityApplication(string name)
        {
            this.name = name;
            creationDate = DateTime.Now;
        }

        #region Fields

        [Key(AutoGenerate = true)]
        [Persistent("GID")]
        private Guid gID;

        [Persistent("Name")]
        private string name;

        [Persistent("CreationDate")]
        private DateTime creationDate;

        [Persistent("Description")]
        private string description;

        //[Aggregated, Association("SecurityRoleUsers", typeof(XPSecurityUser), UseAssociationNameAsIntermediateTableName = true)]
        //internal XPCollection<XPSecurityUser> Users
        //{
        //    get { return GetCollection<XPSecurityUser>("Users"); }
        //}


        //[Association("SecurityApplicationSecuritySecuredType", typeof (XPSecuritySecuredType)), Aggregated]
        //internal XPCollection SecuritySecuredTypes
        //{
        //    get { return GetCollection("SecuritySecuredTypes"); }
        //}



        #endregion

        #region Properties

        [NonPersistent]
        public Guid GID
        {
            get { return gID; }
            set
            {
                if (gID != value)
                {
                    Guid OldValue = gID;
                    gID = value;
                    OnChanged("GID", OldValue, value);
                }
            }
        }

        [NonPersistent]
        public string Name
        {
            get { return name; }
            set
            {
                if (name != value)
                {
                    string OldValue = name;
                    name = value;
                    OnChanged("Name", OldValue, value);
                }
            }
        }

        [NonPersistent]
        public string Description
        {
            get { return description; }
            set
            {
                if (description != value)
                {
                    string OldValue = description;
                    description = value;
                    OnChanged("Description", OldValue, value);
                }
            }
        }

        [NonPersistent]
        public DateTime CreationDate
        {
            get { return creationDate; }
            set
            {
                if (creationDate != value)
                {
                    DateTime OldValue = creationDate;
                    creationDate = value;
                    OnChanged("CreationDate", OldValue, value);
                }
            }
        }

        #endregion
    }
}